package com.twq.types.othertype

/**
 * Created by tangweiqun on 2017/12/7.
 */

trait Logged {
  def log(msg: String): Unit
}

trait LoggedException extends Logged {
  //表示这个trait只能被Exception或者Exception的子类来mixin
  //将this改成self是一样的效果，可以是任何的变量
  this: Exception with Iterable[Int] =>

  def log(): Unit = {
    iterator
    log(getMessage())

  }
}

class NotSelfType

class MyException extends RuntimeException with Iterable[Int] with LoggedException {

  override def getMessage: String = "error"

  override def log(msg: String): Unit = println(s"MyException-${msg}")

  override def iterator: Iterator[Int] = ???
}


object SelfTypes {
  def main(args: Array[String]): Unit = {
    //val f = new NotSelfType with LoggedException

    new MyException().log()
  }
}
